package com.wlw.admin.openeye.utils

import android.content.Context
import android.util.DisplayMetrics

object DisplayManager {

    private var displayMetrics: DisplayMetrics? = null
    private var screenWidth: Int? = null
    private var screenHeight: Int? = null
    private var screenDpi: Int? = null
    fun init(context: Context) {
        displayMetrics = context.resources.displayMetrics
        screenWidth = displayMetrics?.widthPixels
        screenHeight = displayMetrics?.heightPixels
        screenDpi = displayMetrics?.densityDpi
    }

    private val STANDARD_WIDTH = 1080
    private val STANDARD_HEIGHT = 1920
    fun getScreenWidth(): Int? = screenWidth
    fun getScreenHeight(): Int? = screenHeight

    fun getPaintSize(size: Int): Int? = getRealHeight(size)
    fun getRealHeight(px: Int): Int? = getRealHeight(px, STANDARD_HEIGHT.toFloat())
    fun getRealHeight(px: Int, parentHeight: Float): Int = (px / parentHeight * getScreenHeight()!!).toInt()

    fun getRealWidth(px: Int): Int? = getRealWidth(px, STANDARD_WIDTH.toFloat())
    fun getRealWidth(px: Int, parentWidth: Float): Int? = (px / parentWidth * getScreenWidth()!!).toInt()

    fun dip2px(dipValur: Float): Int? {
        val scale = displayMetrics?.density
        return (dipValur * scale!! + 0.5f).toInt()
    }
}